import yaml


def flatten(d, parent_key='', sep='.'):
    """将字典扁平化"""
    items = []
    for k, v in d.items():
        new_key = parent_key + sep + k if parent_key else k
        if isinstance(v, dict):
            items.extend(flatten(v, new_key, sep=sep).items())
        else:
            items.append((new_key, v))
    return dict(items)


def flatten_yaml(obj):
    """将字典扁平化并转为元组列表存储"""
    flattened_obj = flatten(obj)
    return [(k, v) for k, v in flattened_obj.items()]


if __name__ == '__main__':
    with open("sample.yaml", 'r') as f:
        yaml_obj = yaml.load(f, yaml.FullLoader)
        print(flatten_yaml(yaml_obj))
